from mpt_core.mpt import MerklePatriciaTree
from mpt_core.au import *
from mpt_core.encoding import hexdigest_to_nib
from mpt_core.leveldb_handler import LvlDB
import leveldb

# Test
db = leveldb.LevelDB('db_v')


KEY_NIBBLES = [[0 for col in range(64)] for row in range(10)]

KEY_NIBBLES[0] = [5, 15, 0, 12, 14, 11, 6, 6, 15, 15, 12, 8, 6, 15, 3, 8, 13, 9, 5, 2, 7, 8, 6, 12, 6, 13, 6, 9, 6,
                  12, 7, 9, 12, 2, 13, 11, 12, 2, 3, 9, 13, 13, 4, 14, 9, 1, 11, 4, 6, 7, 2, 9, 13, 7, 3, 10, 0, 1, 2, 3, 4, 5, 6, 7]
KEY_NIBBLES[1] = [5, 15, 0, 12, 14, 11, 6, 6, 15, 15, 12, 8, 6, 15, 3, 8, 13, 9, 5, 2, 7, 8, 6, 12, 6, 13, 6, 9, 6, 12,
                  7, 9, 12, 2, 13, 11, 12, 2, 3, 9, 13, 13, 4, 14, 9, 1, 11, 4, 6, 7, 2, 9, 13, 7, 3, 10, 1, 10, 11, 12, 13, 0, 1, 2]
KEY_NIBBLES[2] = [5, 15, 0, 12, 14, 11, 6, 6, 15, 15, 12, 8, 6, 15, 3, 8, 13, 9, 5, 2, 7, 8, 6, 12, 6, 13, 6, 9, 6, 12,
                  7, 9, 12, 2, 13, 11, 12, 2, 3, 9, 13, 13, 4, 14, 9, 1, 11, 4, 6, 7, 2, 9, 13, 7, 3, 10, 1, 10, 11, 12, 14, 3, 4, 5]
KEY_NIBBLES[3] = [5, 15, 0, 12, 14, 11, 6, 6, 15, 15, 12, 8, 6, 15, 3, 8, 13, 9, 5, 2, 7, 8, 6, 12, 6, 13, 6, 9, 6, 12,
                  7, 9, 12, 2, 13, 11, 12, 2, 3, 9, 13, 13, 4, 14, 9, 1, 11, 4, 6, 7, 2, 9, 13, 7, 3, 10, 1, 10, 11, 12, 15, 6, 7, 8]
KEY_NIBBLES[4] = [5, 15, 0, 12, 14, 11, 6, 6, 15, 15, 12, 8, 6, 15, 3, 8, 13, 9, 5, 2, 7, 8, 6, 12, 6, 13, 6, 9, 6,
                  12, 7, 9, 12, 2, 13, 11, 12, 2, 3, 9, 13, 13, 4, 14, 9, 1, 11, 4, 6, 7, 2, 9, 13, 7, 3, 10, 2, 3, 4, 5, 6, 7, 8, 0]
KEY_NIBBLES[5] = [5, 15, 0, 12, 14, 11, 6, 6, 15, 15, 12, 8, 6, 15, 3, 8, 13, 9, 5, 2, 7, 8, 6, 12, 6, 13, 6, 9, 6,
                  12, 7, 9, 12, 2, 13, 11, 12, 2, 3, 9, 13, 13, 4, 14, 9, 1, 11, 4, 6, 7, 2, 9, 13, 7, 3, 10, 2, 3, 4, 5, 6, 7, 8, 1]
KEY_NIBBLES[6] = [5, 15, 0, 12, 14, 11, 6, 6, 15, 15, 12, 8, 6, 15, 3, 8, 13, 9, 5, 2, 7, 8, 6, 12, 6, 13, 6, 9, 6,
                  12, 7, 9, 12, 2, 13, 11, 12, 2, 3, 9, 13, 13, 4, 14, 9, 1, 11, 4, 6, 7, 2, 9, 13, 7, 3, 10, 2, 3, 4, 5, 6, 7, 8, 2]
KEY_NIBBLES[7] = [5, 15, 0, 12, 14, 11, 6, 6, 15, 15, 12, 8, 6, 15, 3, 8, 13, 9, 5, 2, 7, 8, 6, 12, 6, 13, 6, 9, 6,
                  12, 7, 9, 12, 2, 13, 11, 12, 2, 3, 9, 13, 13, 4, 14, 9, 1, 11, 4, 6, 7, 2, 9, 13, 7, 3, 10, 2, 3, 4, 5, 6, 7, 8, 3]

KEY_NIBBLES[8] = [5, 15, 0, 12, 14, 11, 6, 6, 15, 15, 12, 8, 6, 15, 3, 8, 13, 9, 5, 2, 7, 8, 6, 12, 6, 13, 6, 9, 6, 12,
                  7, 9, 12, 2, 13, 11, 12, 2, 3, 9, 13, 13, 4, 14, 9, 1, 11, 4, 6, 7, 2, 9, 13, 7, 3, 10, 2, 7, 15, 11, 5, 7, 14, 9]
KEY_NIBBLES[9] = [5, 15, 0, 12, 14, 11, 6, 6, 15, 15, 12, 8, 6, 15, 3, 8, 13, 9, 5, 2, 7, 8, 6, 12, 6, 13, 6, 9, 6, 12,
                  7, 9, 12, 2, 13, 11, 12, 2, 3, 9, 13, 13, 4, 14, 9, 1, 11, 4, 6, 7, 2, 9, 13, 7, 3, 10, 2, 7, 15, 11, 5, 7, 14, 9]


authen_tuple_0 = presense(db, KEY_NIBBLES[0])

root_hash = db.get(b'root_hash')

authentication(root_hash, authen_tuple_0, KEY_NIBBLES[0])
